package org.scs.carleton.ca.pgdt.core.internal.parser;

import java.util.ArrayList;
import java.util.List;

import org.scs.carleton.ca.pgdt.core.parser.nodes.IASTList;
import org.scs.carleton.ca.pgdt.core.parser.nodes.IASTNode;
import org.scs.carleton.ca.pgdt.core.visitor.PrologVisitor;

/**
 * Physical implementation of a prolog list
 * 
 * @author tessierj
 *
 */
public class ASTList extends ASTNode implements IASTList {
	private List<IASTNode> elements;
	
	public ASTList(ASTTranslationUnit translationUnit, int type) {
		super(translationUnit, type);
		elements = new ArrayList<IASTNode>(10);
	}

	public void addElement(IASTNode node) {
		elements.add(node);
	}
	
	@Override
	public List<IASTNode> getElements() {
		return elements;
	}

	@SuppressWarnings("nls")
	public String toString() {
		return "List " + " from " + getStartOffset() + " to " + getEndOffset();
	}
	
	@Override
	public boolean accept(PrologVisitor visitor) {
		boolean visitChildren = visitor.visit(this);
		
		if (visitor.visit(this)) {
			//If the visitor wants to visit this node...
			for (IASTNode node : elements) {
				node.accept(visitor);
			}
		}
		
		return visitChildren;
	}
}
